package me.jianghs.controller;

import me.jianghs.service.StudentService;
import me.jianghs.thrift.Student;
import org.apache.thrift.TException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

@RestController
@RequestMapping("/demo")
public class DemoController {
    @Autowired
    private StudentService studentService;
    private Logger logger = LoggerFactory.getLogger(getClass());

    @GetMapping("/echo")
    public String echo() {
        logger.info("hello echo");
        return "echo";
    }

    @GetMapping("/hello")
    public String hello() {
        return "hello";
    }

    @GetMapping("/get")
    public Student get(String name) throws TException, IOException {
        return studentService.getStudentByName(name);
    }

    @GetMapping("/save")
    public void save() {
        //直接模拟前端传递的数据
        Student student = new Student();
        student.setName("AAA");
        student.setAge(10);
        student.setAddress("BBB");
        //调用保存服务
        studentService.save(student);
    }
}
